package com.demo.connectdbtest.datasourceconfig;
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.PlatformTransactionManager;
//
//import javax.sql.DataSource;
//
///**
// * @author: xhf
// * @date: 2021/11/19
// * @desc: mysql统计数据源
// **/
//@Configuration
//@MapperScan(basePackages = "com.sanlian.popo.activity.admin.module.*.statisticsMapper", sqlSessionTemplateRef="statisticsSqlSessionTemplate")
//public class ConfigurationDatasourceStatistics {
//
//    @Bean(name = "statisticsDataSource")
//    @ConfigurationProperties("spring.datasource.statistics")
//    public DataSource slaveDataSource(){
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "statisticsSqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("statisticsDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
//        sessionFactoryBean.setDataSource(dataSource);
//        Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/statisticsMapper/*.xml");
//        sessionFactoryBean.setMapperLocations(resources);
//        return sessionFactoryBean.getObject();
//    }
//    @Bean(name = "statisticsTransactionManager")
//    public PlatformTransactionManager mangoTransactionManager(@Qualifier("statisticsDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//    @Bean(name = "statisticsSqlSessionTemplate")
//    public SqlSessionTemplate mangoSqlSessionTemplate(@Qualifier("statisticsSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//}
